package com.woniuxy01;

/**
 * @author 作者
 * @create 2025-06-06 10:37
 */
public class StudentService {

    public static Student[] students;

    static {
        students = new Student[3];
        students[0] = new Student(1,"a","aaa",11,"male");
        students[1] = new Student(2,"b","bbb",12,"female");
        students[2] = new Student(3,"c","ccc",13,"male");
    }

    public static Student login03(String name,String pwd){
        Student student = null;
        for(Student stu : students ){
            if(stu.getName().equals(name)){
                student = stu;
                break;
            }
        }
        if(student == null){
            throw new UserNameNotExistsException("用户名不存在");
        }
        if(!student.getPwd().equals(pwd)){
            throw new PasswordErrorException("密码错误");
        }
        return student;

    }
    public static Student login02(String name,String pwd){
        for(Student student : students ){
            if(student.getName().equals(name)&&student.getPwd().equals(pwd)){
                return student;
            }
        }
       throw new RuntimeException("登录失败");
    }

    public static Student login01(String name,String pwd){
        for(Student student : students ){
            if(student.getName().equals(name)&&student.getPwd().equals(pwd)){
                return student;
            }
        }
        return null;
    }

}
